package main.com.oaer.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import main.com.oaer.service.PurviewService;

public class PrepareInterceptor extends HandlerInterceptorAdapter{
   
	@Autowired
	PurviewService purviewService;
	
	@Override
	public boolean preHandle(HttpServletRequest request, 
			HttpServletResponse response, Object handler) throws java.lang.Exception{
		HttpSession session = request.getSession();
		String actionName = request.getRequestURI().replace(request.getContextPath(),"");
		if(session.getAttribute("userMap")==null){
			if(("/").equals(actionName) 
					|| ("/index").equals(actionName)
					|| (actionName!=null&&actionName.startsWith("/common"))
					|| ("/index/login").equals(actionName)){
				return true;
			}else{
				response.sendRedirect("/index");
			    return false;
			}
		}else 
		return true;
	}
	
	
}
